package com.ygl.consumer.controller;

import com.ygl.api.User;
import com.ygl.consumer.feign.ServiceProviderFeign;
import com.ygl.consumer.feign.ServiceProviderFeignExtend;
import com.ygl.consumer.feign.WiiFeign;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author yanggld
 * @Date 2019/11/22-10:36
 * @Description
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RestController
public class FeignController {

	private final ServiceProviderFeign serviceProviderFeign;

	private final ServiceProviderFeignExtend serviceProviderFeignExtend;

	/**
	 * 通过feign，实现服务间调用
	 * @return
	 */
	@GetMapping("/restByFeign")
	public String restByFeign(){
		String name = serviceProviderFeign.getName();
		return name;
	}

	/**
	 * 通过feign继承，实现服务间调用
	 * @return
	 */
	@GetMapping("/restByFeignExtend")
	public String restByFeignExtend(){
		String name = serviceProviderFeignExtend.findName("token123");
		return name;
	}

	/**
	 * 通过feign继承，实现服务间调用
	 * @return
	 */
	@GetMapping("/findUser")
	public User findUser(){
		long start = System.currentTimeMillis();
		User user = new User();
		user.setId("12611");
		user.setName("ygl");
		User result = serviceProviderFeignExtend.findUser(user);
		long end = System.currentTimeMillis();
		log.info("findUser耗时:{}",(end-start));
		return result;
	}

	@Autowired
	private WiiFeign wiiFeign;

	@GetMapping("/index")
	public Object index(){
		return wiiFeign.index();
	}
}
